package com.example.experiment3.configuration;

import com.example.experiment3.controller.MyController;
import com.example.experiment3.service.MyService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration
@EnableScheduling
public class MyConfig {

    @Scheduled(cron="0 0 1 * * *")
    public void fetchData(){
        MyController.records=MyService.CsvToCsvrecord();
    }

    @Bean
    public CommandLineRunner commandLineRunner(){
        return  (res) -> {
            MyController.records=MyService.CsvToCsvrecord();

        };
    }
}
